﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
<script>
    var spaceId = $.request("spaceId");
    var F_SiteId = $.request("F_SiteId");
    var type = $.request("type");
    $(function () {
        if (type == "disabled") {
            document.getElementById("topPanel").style.display = "none";
        }
        getItemList();
    })
    function gridList(ItemList) {
        var $gridList = $("#ServerGridList");
        var queryJson = {
            F_SpaceId: spaceId
        }
        $gridList.dataGrid({
            url: "/SiteManage/ServicesCost/GetGridJson",
            postData: { queryJson: JSON.stringify(queryJson) },
            height: $(window).height() - 196,
            colModel: [
                { label: '编号', name: 'F_Id', hidden: true },
                {
                    label: '增值服务', name: 'F_CostId', width: 100, align: 'left',
                    formatter: function (cellvalue) {
                        return FMDictionaries(ItemList.ServicesCost, cellvalue);
                    }
                },
                { label: '费用', name: 'F_Cost', width: 100, align: 'left' },
                { label: '价格单位', name: 'F_CostUnits', width: 100, align: 'left' },
                { label: '服务名称', name: 'F_CategoryName', width: 100, align: 'left' },
                { label: '意见', name: 'F_Content', width: 100, align: 'left' }
            ],
            pager: "#gridPager",
            sortname: 'F_Id desc',
            viewrecords: true
        });
         $("#btn_search").click(function () {
            $gridList.jqGrid('setGridParam', {
                postData: { keyword: $("#txt_keyword").val() },
            }).trigger('reloadGrid');
        });
    }
    function FMDictionaries(state, cellvalue) {
        if (cellvalue != undefined && cellvalue != null) {
            for (var i = 0; i < state.length; i++) {
                if (state[i].F_ItemCode.toString() == cellvalue.toString()) {
                    cellvalue = state[i].F_ItemName;
                    break;
                }
            }
        }
        else
            cellvalue = "";
        return cellvalue;
    }
    function getItemList() {
        $.ajax({
            url: "/SiteManage/Site/GetItemListJson",
            dataType: "json",
            async: false,
            success: function (data) {
                gridList(data);
            }, error: function (XMLHttpRequest, textStatus, errorThrown) {
                console.log(XMLHttpRequest);
                console.log(textStatus);
                console.log(errorThrown);
            }
        });
    }
    function btn_add() {
        console.log("index:" + F_SiteId);
        $.modalOpen({
            id: "ServicesCostForm",
            title: "新增增值服务",
            url: "/SiteManage/ServicesCost/Form?spaceId=" + spaceId + "&F_SiteId=" + F_SiteId,
            width: "800px",
            height: "600px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    function btn_edit() {
        var keyValue = $("#ServerGridList").jqGridRowValue().F_Id;
        if (keyValue) {
            $.modalOpen({
                id: "edit_ServicesCostForm",
                title: "修改增值服务",
                url: "/SiteManage/ServicesCost/Form?keyValue=" + keyValue + "&spaceId=" + spaceId + "&F_SiteId=" + F_SiteId,
                width: "1000px",
                height: "520px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitForm();
                }
            });
        } else {
            $.modalAlert("请先选择您要修改的数据！", "warning");
        }
    }
    function btn_delete() {
        var keyValue = $("#ServerGridList").jqGridRowValue().F_Id;
        if (keyValue) {
            $.deleteForm({
                url: "/SiteManage/ServicesCost/DeleteForm",
                param: { keyValue: $("#ServerGridList").jqGridRowValue().F_Id },
                success: function () {
                    $.currentWindow().$("#ServerGridList").trigger("reloadGrid");
                }
            })
        } else {
            $.modalAlert("请先选择您要删除数据！", "warning");
        }
    }

    function submitForm() {
        $.modalFrameClose(window.name);
    }
</script>

<div class="topPanel" id="topPanel">
    <div class="search">
        <table>
            <tr>
                <td>
                    <div style="margin: 0 10px 0 10px;">
                        <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-eraser"></i>添加增值服务</a>
                        <a id="NF-edit" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改增值服务</a>
                        <a id="NF-delete" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除增值服务</a>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>

<div class="gridPanel">
    <table id="ServerGridList"></table>
    <div id="gridPager"></div>
</div>


